﻿/*****************************************************************//**
 * @file    FITKGraphObjectInertia.h
 * @brief   Graph object for inertia.
 *
 * @author  ChengHaotian (yeguangbaozi@foxmail.com)
 * @date    2024-05-24
 *********************************************************************/

#ifndef __FITKGRAPHOBJECTINERTIA_H__
#define __FITKGRAPHOBJECTINERTIA_H__

#include "FITKGraphObjectMarkBase.h"

#include "FITKVTKGraphAdaptorAPI.h"

// Forward declaration
class vtkPoints;
class vtkCellArray;
class vtkPolyData;
class vtkUnstructuredGrid;
class vtkSelectionNode;
class vtkSelection;
class vtkExtractSelection;
class vtkIdTypeArray;
class vtkIntArray;
class vtkCell;
class vtkPointSource;
class vtkGlyph3D;

class FITKGraphActor;

namespace Interface
{
    class FITKAbaAbstractInertia;
    class FITKBoundaryLocation;
}

namespace Exchange
{
    /**
     * @brief   Graph object for 'inertia'.
     * @author  ChengHaotian (yeguangbaozi@foxmail.com)
     * @date    2024-05-24
     */
    class FITKVTKGRAPHADAPTORAPI FITKGraphObjectInertia : public FITKGraphObjectMarkBase
    {
        // Regist
        FITKGraphObjectRegist(FITKGraphObjectInertia, FITKGraphObjectMarkBase);
        FITKCLASS(Exchange, FITKGraphObjectInertia);

    public:
        /**
         * @brief   Constructor.
         * @param   caseData: The case data
         * @param   inertiaData: The inertia data object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        FITKGraphObjectInertia(AbaqusData::FITKDataCase* caseData, Interface::FITKAbaAbstractInertia* inertiaData);

        /**
         * @brief   Destructor.[virtual]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        virtual ~FITKGraphObjectInertia();

        /**
         * @brief   Show or hide graph object.[virtual][override]
         * @param   visibility: The visibility of graph object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        virtual void setVisible(bool visibility) override;

        /**
         * @brief   Highlight the interactions or constraint graph actors.[virtual][override]
         * @param   color: The given color for highlighting this time[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        virtual void highlight(QColor color = QColor()) override;

        /**
         * @brief   Dis-highlight the interactions or constraint graph actors.[virtual][override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        virtual void disHighlight() override;

        /**
         * @brief   Update all graph actors.[virtual][override]
         * @param   forceUpdate: Force update[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        virtual void update(bool forceUpdate = false) override;

        /**
         * @brief   Update the visibility with data object's visibility.[virtual][override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        virtual void updateVisibility() override;

        /**
         * @brief   Simplified the graph object if necessary.[virtual][override]
         * @param   enabled: Enabled simplified flag
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        virtual void simplified(bool enabled) override;

        /**
         * @brief   If the graph object has relation with the given data object id.[virtual][override]
         * @param   dataObjId: The data object id
         * @return  Has relation
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        virtual bool isRelatedTo(int dataObjId) override;

    protected:
        /**
         * @brief   Initialize.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        void init();

        /**
         * @brief   Initialize the actors.[virtual]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-30
         */
        virtual void initActors();

        /**
         * @brief   Clear the model ids and the visibility hash.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        void clearModelsInfo() override;

        /**
         * @brief   Clear the data.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        void clearData() override;

        /**
         * @brief   Generate inertia actor.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        void generateGraph() override;

        /**
         * @brief   Generate the poly data for the inertia.[virtual]
         * @param   inertiaData: The inertia data object
         * @return  Is OK
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-28
         */
        virtual bool generatePolyData(Interface::FITKBoundaryLocation* inertiaData);

        /**
         * @brief   Get the visibility from the data object.[override]
         * @return  The visibility
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-28
         */
        bool getDataVisibility() override;

    protected:
        /**
         * @brief   The glyph point source.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-28
         */
        vtkPointSource* m_pointSource{ nullptr };

        /**
         * @brief   The glyph size of the shape.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        double m_glyphSize = 25.;

        /**
         * @brief   The points data for inertia glyphs.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        vtkPoints* m_points{ nullptr };

        /**
         * @brief   The glyph filter.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-28
         */
        vtkGlyph3D* m_glyph{ nullptr };

        /**
         * @brief   The grid data for inertia glyph.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        vtkUnstructuredGrid* m_ugrid{ nullptr };

        /**
         * @brief   The model id data array.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        vtkIntArray* m_modelIdArray{ nullptr };

        /**
         * @brief   The graph actor for inertia glyphs.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        FITKGraphActor* m_fActor{ nullptr };

        /**
         * @brief   The selection node for extract mesh grid.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        vtkSelectionNode* m_selectNode{ nullptr };

        /**
         * @brief   The selection for vtkSelectionNode.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        vtkSelection* m_section{ nullptr };

        /**
         * @brief   The mesh grid extractor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        vtkExtractSelection* m_extractSelection{ nullptr };

        /**
         * @brief   The indice array of extract id.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        vtkIdTypeArray* m_idArray{ nullptr };

        /**
         * @brief   All model ids for surface of the graph object.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        QList<int> m_modelIds;

        /**
         * @brief   The visibility of all components' parent models.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        QHash<int, bool> m_modelVisibilityHash;

        /**
         * @brief   The inertia's component id.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-24
         */
        int m_componentId = -1;

        /**
         * @brief   The sub set ids of the comp set or surface.( the location of the inertia )
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-18
         */
        QList<int> m_subSetIds;

    };
}   // namespace Exchange

#endif // __FITKGRAPHOBJECTINERTIA_H__
